package com.sunlands.zlcx.usercenter.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.domain.UsersLearnTimingDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(value = "学习计时VO")
public class UsersLearnTimingVO implements Serializable {

    private static final long serialVersionUID = -902247963301768616L;
    private Long id;

    /**
     * 学习生活名称
     */
    @ApiModelProperty(value = "学习计时名称")
    private String learnName;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private Long userId;

    /**
     * 目标id
     */
    @ApiModelProperty(value = "目标id")
    private Long targetId;

    /**
     * 状态
     */
    @ApiModelProperty(value = "状态")
    private Integer status;


    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    /**
     * 学习分钟数
     */
    @ApiModelProperty(value = "学习分钟数")
    private Integer studyMinutes;

    /**
     * 星期几
     */
    @ApiModelProperty(value = "周几")
    private String week;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    /**
     * {@link com.sunlands.zlcx.usercenter.domain.UsersLearnTimingDO.TypeEnums}
     * 类型id
     */
    @ApiModelProperty(value = "类型id,1:学习计时，10:连麦学习")
    private Integer type;

    /**
     * {@link com.sunlands.zlcx.usercenter.domain.UsersLearnTimingDO.TypeEnums}
     * 类型名称
     */
    @ApiModelProperty(value = "类型名称")
    private String typeName;

    /**
     * 统计时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date countTime;

    @ApiModelProperty(value = "学习开始时的排名")
    private Integer startSort;

    @ApiModelProperty(value = "学习结束时的排名")
    private Integer endSort;

    public static UsersLearnTimingVO from(UsersLearnTimingDO usersLearnTimingDO) {
        return Objects.isNull(usersLearnTimingDO)? null : UsersLearnTimingVO.builder().id(usersLearnTimingDO.getId())
                .createTime(usersLearnTimingDO.getCreateTime())
                .startTime(usersLearnTimingDO.getStartTime())
                .endTime(usersLearnTimingDO.getEndTime())
                .status(usersLearnTimingDO.getStatus())
                .userId(usersLearnTimingDO.getUserId())
                .targetId(usersLearnTimingDO.getTargetId())
                .learnName(usersLearnTimingDO.getLearnName())
                .studyMinutes(usersLearnTimingDO.getStudyMinutes())
                .week(usersLearnTimingDO.getWeek())
                .type(usersLearnTimingDO.getType())
                .typeName(UsersLearnTimingDO.TypeEnums.create(usersLearnTimingDO.getType()).getTitle())
                .countTime(usersLearnTimingDO.getCountTime())
                .build();
    }
}
